/**
 * 
 */
package br.pucpr.server.jogo;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.Socket;

import br.pucpr.server.Property;

/**
 * @author 2ony
 *
 */
public class ThreadJogoMaestro extends Thread {
	
	private int porta;
	private String ipServidor;
	private Socket socket;
	private BufferedInputStream in;
	private BufferedOutputStream out;
		
	@Override
	public void run() {
		porta = Property.obterInstancia().obterPortaTransferencia();
		ipServidor = Property.obterInstancia().obterIpServidor();

		try {
			socket = new Socket(ipServidor, porta);
					
			byte[] buffer = new byte[1024 * 50];

			in = new BufferedInputStream(new FileInputStream("senhaplay.dat"));

			out = new BufferedOutputStream(socket.getOutputStream());

			int len = 0;
			while ((len = in.read(buffer)) > 0) {
				out.write(buffer, 0, len);
			}
			out.flush();
			out.close();
						
		}

		catch (IOException e) {
			System.err.println("Nao consegui conexao de I/O com o host"
					+ ipServidor);
			System.exit(1);
		}
	}


}
